package com.team5.mapper;
import com.team5.entity.SysLog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface SysLogMapper {
    @Select("select * from SYS_LOG where id = #{id}")
    SysLog findById(Long id);

    @Select("select * from SYS_LOG")
    List<SysLog> findAll();

    @Insert("insert into SYS_LOG (id, explain, url, startTime, endTime, tableName) " +
            "values (#{id}, #{explain}, #{url}, #{startTime}, #{endTime}, #{tableName})")
    @SelectKey(statement = "SELECT seq_log.NEXTVAL FROM DUAL", keyProperty = "id", before = true, resultType = int.class)
    int insertSysLog(SysLog sysLog);

    @Update("update SYS_LOG set " +
            "explain = #{sysLog.explain}, " +
            "url = #{sysLog.url}, " +
            "startTime = #{sysLog.startTime}, " +
            "endTime = #{sysLog.endTime}, " +
            "tableName = #{sysLog.tableName} " +
            "where id = #{sysLog.id}")
    int updateSysLog(@Param("sysLog") SysLog sysLog);

    @Delete("delete from SYS_LOG where id = #{id}")
    int deleteSysLog(Long id);
}
